﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TaggerApp.ORD;
using TaggerApp.MSTagRefService;
using TaggerApp.Authentication;
using System.Data.SqlClient;
using System.Configuration;
using TaggerApp.Authentication;

namespace TaggerApp.Admin.Pages.LoanDevice
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //User myUser = (User)Session["user"];
            //if (myUser == null)
            //{
            //    Response.Redirect("~/Pages/Login");
            //}
            //else if (!myUser.Role.Equals("Admin"))
            //{
            //    Response.Redirect("~/Pages/Unauthorized/Unauthorized.aspx");
            //}

            txtCurrentTime.Text= System.DateTime.Now.ToString();
            Global title = new Global();
            title.GetTitleFromDB();
            Page.Title = "Loan a Device - " + title.appName; 
        }

        protected void btnClear_Click(object sender, EventArgs e)
        {
            txtBoxDeviceID.Text = "";
            txtBoxBorrowerName.Text = "";
            txtBoxEmailAddress.Text = "";
            txtBoxLoanerName.Text = "";
            txtBoxLoanerEmail.Text = "";
            txtBoxPhoneNumber.Text = "";
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            using (mstaggerEntities entities = new mstaggerEntities())
            {
                //Insert a Record
                //===================================
                tblLoanDevice loaner = new tblLoanDevice();
                //fill the object with data

                loaner.productID = Convert.ToInt32(txtBoxDeviceID.Text);
                loaner.dateBorrow = Convert.ToDateTime(txtCurrentTime.Text);
                loaner.loanTimeID = loantimeDropDownList.SelectedIndex;
                loaner.loanerName = txtBoxLoanerName.Text;
                loaner.loanerEmail = txtBoxLoanerEmail.Text;
                loaner.borrowerName = txtBoxBorrowerName.Text;
                loaner.borrowerPhone = txtBoxPhoneNumber.Text;
                loaner.borrowerEmail = txtBoxEmailAddress.Text;
                //Call the method to add the object to the table
                entities.tblLoanDevices.Add(loaner);
                //Save the changes to the DB
                entities.SaveChanges();
            }
        }


    }
}